package org.csu.pm.util;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20210111.SmsClient;
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SmsUtil {
    public static boolean sendCaptcha(String phone, String captcha) {
        try {
            Credential cred = new Credential("AKIDay5wVnnW2GCqDI5bpmSrzqPhiV1FCrFM", "tVpthEYbMpjRt4zf7JH2e18za2MRN7an");
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("sms.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            SmsClient client = new SmsClient(cred, "ap-guangzhou", clientProfile);
            SendSmsRequest req = new SendSmsRequest();
            String[] phoneNumberSet1 = {phone};
            req.setPhoneNumberSet(phoneNumberSet1);
            req.setSmsSdkAppId("1400673483");
            req.setSignName("0xffff个人网站");
            req.setTemplateId("1390064");
            String[] templateParamSet1 = {captcha};
            req.setTemplateParamSet(templateParamSet1);
            client.SendSms(req);
            log.info("发送验证码 " + captcha + " 至 " + phone);
        } catch (TencentCloudSDKException e) {
            System.out.println(e);
            return false;
        }
        return true;
    }
}
